package com.zyy.java8.samples.stream;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.stream.IntStream;

/**
 * @author zhangyiying
 * @ClassName: Streams13
 * @Description:
 * @date 2022/2/7 15:20
 */
public class Streams13 {

    public static void main(String[] args) throws NoSuchAlgorithmException {
        //SecureRandom secureRandom = new SecureRandom(new byte[]{1, 3, 3, 7}); 这种方式种子写死了结果可以预知
        //建议使用这种方式生成随机数 SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
//        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
        SecureRandom secureRandom = new SecureRandom(new byte[]{1, 3, 3, 7});
        int[] randoms = IntStream.generate(secureRandom::nextInt)
                        .filter(n -> n > 0)
                        .limit(10)
                        .toArray();
        System.out.println(Arrays.toString(randoms));

//        SecureRandom secureRandom1 = SecureRandom.getInstance("SHA1PRNG");
//        int[] randoms1 = IntStream.generate(secureRandom1::nextInt)
//                .filter(n -> n > 0)
//                .limit(10)
//                .toArray();
//        System.out.println(Arrays.toString(randoms1));

        int[] nums = IntStream.iterate(1, n -> n * 2)
                                .limit(11)
                                .toArray();
        System.out.println(Arrays.toString(nums));
    }
}
